// pages/share/detail/detail.js
var util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentIndex:0,
    cardRightIn:false,
    cardLeftIn:false,
    indicatorDots: true,
    mode: 'aspectFill',
    first:[
      {
      }
    ],

    interval: 5000,
    duration: 500,
    currentTab: 0, //预设当前项的值
    scrollLeft: 0, //tab标题的滚动条位置 */
    showModal: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("options=",options)
    this.setData({
      title:options.title,
      wenan:options.wenan,
      didian:options.didian,
      time:options.time,
      agree:options.agree,
      agreeNum:options.agreeNum,
      commentNum:options.commentNum,
      tag:options.tag,
      comment:options.comment,
      touxiang:options.touxiang,
      zuozhe:options.zuozhe,
      name_01:options.name_01,
      txt_01:options.txt_01,
      name_02:options.name_02,
      txt_02:options.txt_02,
      name_03:options.name_03,
      txt_03:options.txt_03,
      name_04:options.name_04,
      txt_04:options.txt_04,
      images:options.images,
    })

    let list=[
      {
        _id: "dvhhicWM83uNxzrby",
        // agree:"false",
        agreeNum: 293,
        commentNum: 56,
      }
    ]
    for(let i of list){
      i.fromNow = util.fromNow(i.createtime)
    }
    this.setData({
      list
    })
  },

  navigateTocomment: function (event) {
    wx.navigateTo({
      url: '/pages/share/comment/comment',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   
  },

  // 点赞功能
  toAgree:function(e){
    let id = e.currentTarget.dataset.id;
    let list = this.data.list
    for(let i of list){
      if(i._id == id){
        i.agree = !i.agree
      }
      if (i._id == id && i.agree){
        i.agreeNum = i.agreeNum + 1        
      } else if (i._id == id && !i.agree){
        i.agreeNum = i.agreeNum - 1   
      }  
      this.setData({ list })       
    }
  },

  toComment:function(){
    console.log('comment')
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})